<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript" src="js/map.js" ></script>
<?php if (isset($add)) echo "<h2>Thêm Khách Sạn</h2>"; else echo "<h2>Thay đổi thông tin khách sạn</h2>";?>
<form name="edit_hotel" action="?act=createOrModifyHotel&hotel_id=<?php echo (isset($hotel_id)? $hotel_id:"")  ?>" method="POST" onsubmit="return validate_values()" enctype="multipart/form-data">
	<div class='row_field'>
    	<div class='label'>
			<label for="hotel_name">Tên Khách Sạn(*):</label>
        </div>
        <div class='field'>
			<input class='inputbox' type="text" id="hotel_name" name="hotel_name" value="<?php echo $hotel->getname() ?>">
        </div>
	</div>
	
	<div class='row_field'>
    	<div class='label'>
			<label for="address">Địa chỉ(*):</label>
        </div>
        <div class='field'>
			<textarea class='inputbox' id="address" name="address"><?php echo $hotel->getaddress() ?></textarea>
        </div>
	</div>
	
	<div class='row_field'>
    	<div class='label'>
			<label for="thumbnail">Hình đại diện:</label>
        </div>
		<div class='field'>
			<input class='inputbox' type="file" id="thumbnail" name="thumbnail">
        </div>
    </div>

	<div class='row_field'>
    	<?php
			$thm_pic = new Picture();
			$thumbnail = $hotel->getthm_picture();
			if ($thumbnail) {
				$thm_pic->select($thumbnail);
			}
				
			echo "<div><img id='thm_picture' src='".$thm_pic->getPath()."'></div>"		
		?>
    </div>
	
	<div class='row_field'>
    	<div class='label'>
			<label for="country">Quốc Gia(*):</label>
		</div>
		<?php $locations = Location::getAllLocations(); ?>		
		<div class='field'>
            <select id="location" name="location">
                <?php				
    
                    foreach ($locations as $location) {
                    ?>
                    <option value="<?php echo $location->getid()?>" <?php echo ($location->getid()==$hotel->getlocation())?"selected='selected'":""?>>					
                        <?php echo $location->getname() ?>
                    </option>
                    <?
                    }
                ?>
            </select>
        </div>
	</div>
    <script>
        $(document).ready(function() 
        {
            <?
				$txt_latx = $hotel->getlatitude_x();
				$txt_laty = $hotel->getlatitude_y();
                if (empty($txt_latx) && empty($txt_laty)) {
                    $txt_latx = "16.066649";
                    $txt_laty = "108.187494";
				}
				$hinh = "/images/5stars.png";
            ?>
            var currentLocation = new google.maps.LatLng(<?=$txt_latx?>,<?=$txt_laty?>);
			
            image =  new google.maps.MarkerImage("<?=$hinh?>",
              // This marker is 20 pixels wide by 32 pixels tall.
              new google.maps.Size(32, 37),
              // The origin for this image is 0,0.
              new google.maps.Point(0,0),
              // The anchor for this image is the base of the flagpole at 0,32.
              new google.maps.Point(0, 0)); 
            
            initialize(currentLocation,"map_canvas_admin","txt_latx","txt_laty");
            placeMarker(currentLocation);
        });
    </script>
    <div class='row_field'>
        <div class='label'>Tọa độ: </div>
        <div class='field'>
            <input type="hidden" name="txt_latx" id="txt_latx" value="<?=$txt_latx?>" />
            <input type="hidden" name="txt_laty" id="txt_laty" value="<?=$txt_laty?>" />
            <input type="text" name="txt_address" id="txt_address" value="Đà Nẵng" class='inputbox' /> <input type='button' class='inputbox' value='Tìm' style='width:40px' onclick="codeAddress('txt_address','txt_latx','txt_laty')" />
        </div>
    </div> 
    <div class='row_field'>
		<div id="map_canvas_admin" style="width: 600px; height: 400px; z-index:0"></div>
    </div>
	
	<div class='row_field'>
    	<div class='label'>
			<label>Hạng(*):</label>
        </div>
        <div class='field'>
			<input class='inputbox' type="text" id="star" name="star" value="<?php echo $hotel->getstar() ?>">
        </div>
	</div>
	
	<div class='row_field'>
	    <div class='label'>
			<label for="description">Miêu tả Địa Điểm(*):</label>
		</div>
		<?php
		include("../fckeditor.php");
		$sBasePath = $_SERVER['PHP_SELF'] ;
		$sBasePath = substr( $sBasePath, 0, strpos( $sBasePath, "admin" ) ) ;
		
		$oFCKeditor = new FCKeditor('description') ;
		$oFCKeditor->BasePath	= $sBasePath ;
		$oFCKeditor->Value		= $hotel->getdescription();
		$oFCKeditor->Height		= 300;
		$oFCKeditor->Create() ;
		?>
	</div>
	
	<?php // facility list for hotel ?>
	<?php
		echo "<div class='row_field'>";
		echo "<table>";
		$facilities = Facility::getAllFacilities();
		$hotel_facility_ids = array();
		if (isset($hotel_id)) {
			$hotel_facilities = HotelFacility::getAllFacilitiesForHotel($hotel_id);
			foreach ($hotel_facilities as $facility)
				$hotel_facility_ids[] = $facility->getid();
		}
		foreach ($facilities as $category => $facility_list) {
			echo "<tr class='tr_border'>";
			echo "<td align='right' valign='top'><div style='padding:10px'><b>".$category."</b></div></td>";
			echo "<td align='left'>";
			foreach ($facility_list as $facility) {
				echo "<div style='display:inline-block;float:left;padding:5px;width:210px;'>";
				echo "<input type='checkbox' id='facility_".$facility->getid()."' name='facility_".$facility->getid()."'";
				if (in_array($facility->getid(), $hotel_facility_ids))
					echo "checked='checked'";
				echo " />";
				echo "<label for='facility_".$facility->getid()."'>".$facility->getdescription()."</lable>";
				echo "</div>";
			}

			echo "<div style='clear:both'></div>";
			echo "</td>";
			echo "</tr>";
		}
		echo "</table>";
		echo "</div>";
	
	?>
	<div class='row_field'>
    	<div class='label'>
			<label for="active">Hiệu lực:</label>
        </div>
        <div class='field'>
			<input type="checkbox" id="active" name="active" <?php if ($hotel->getactive() == 1 || isset($add)) echo 'checked="true"'?>>
        </div>
	</div>
		
	<div class='row_field'><p>(*) Thông tin bắt buộc</p></div>
	<div class='row_field'>
		<input type="submit" value="Save">
		<input type="reset" value="Reset">
	</div>
	
</form>
<script type="text/javascript">
	function validate_values() {
		name = $('#hotel_name').val();
		description = $('#description').val();
		
		message = "Các mục sau đây là bắt buộc hoặc sai giá trị: \n";
		ok = true;
		if (name == "") {
			message += "Tên Địa Điểm \n";
			ok = false;
		}
		if (!ok) alert(message);
		return ok;
	}
</script>

<style>
	.tr_border td
	{
		border:1px solid #ccc;
	}
</style>